﻿using EF6WithSqlDemo.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EF6WithSqlDemo
{
    class InheritanceContext : DbContext
    {
        public DbSet<PersonBase> Persons { get; set; }

        public InheritanceContext()
            : base("sqlconn")
        {

        }

        protected override void OnModelCreating(DbModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity<PersonBase>().HasKey(x => x.PersonID);
            builder.Entity<PersonBase>().Property(x => x.PersonID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            // TPT mapping
            builder.Entity<PersonBase>().ToTable("tpt.Person");
            builder.Entity<Worker>().ToTable("tpt.Worker");
            builder.Entity<Retired>().ToTable("tpt.Retired");
        }
    }
}
